@using Acme.BookStore.FormWhxDto.StorehouseDto
@using Volo.Abp.Application.Dtos
@inject IStorehouseService StorehouseService

<Select TItem="WarehouseManagerDto"
        TValue="string"
        DataSource="@Managers"
        @bind-Value="@Value"
        ValueName="@nameof(WarehouseManagerDto.Name)"
        LabelName="@nameof(WarehouseManagerDto.Name)"
        OnSearch="@HandleSearch"
        ShowSearch="true"
        AllowClear="true"
        Style="width: 100%"
        Placeholder="请选择仓库主管">
</Select>

@code {
    [Parameter]
    public string Value { get; set; }

    [Parameter]
    public EventCallback<string> ValueChanged { get; set; }

    private List<WarehouseManagerDto> Managers { get; set; } = new();

    protected override async Task OnInitializedAsync()
    {
        await LoadManagers();
    }

    private async Task LoadManagers(string searchText = null)
    {
        if (string.IsNullOrWhiteSpace(searchText))
        {
            var result = await StorehouseService.GetWarehouseManagerAsync();
            Managers = result.Items.ToList();
        }
        else
        {
            var result = await StorehouseService.SearchWarehouseManagerAsync(searchText);
            Managers = result.Items.ToList();
        }

        StateHasChanged();
    }

    private async Task HandleSearch(string searchText)
    {
        await LoadManagers(searchText);
    }
} 